import axios from "axios";
import NProgress from "nprogress";
import store from "store/store"
const sphIns = axios.create({
    baseURL: '/sph',
    timeout: 3000
})

import uuidFn from '@/util/uuid'
//添加拦截器
sphIns.interceptors.request.use(function (config) {
    //在请求开始前，开启进度条
    NProgress.start()
    //为所有使用sph开头的请求添加请求头userTempId
    config.headers.userTempId = uuidFn()
    //为所有使用sph的请求加请求头token
    if (store.state.user.token)
        config.headers.token = store.state.user.token

    return config;
})
sphIns.interceptors.response.use(function (response) {
    NProgress.done()
    return response.data;
}, function (error) {
    NProgress.done()
    return Promise.reject(error);
})

export default sphIns